package javasec.contempt.consoles;

import java.io.InputStream;
import java.io.OutputStream;

import javasec.contempt.data.SeedConnector;
import javasec.contempt.data.SeedNotifier;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.console.IOConsole;
import org.eclipse.ui.console.IOConsoleInputStream;
import org.eclipse.ui.console.IOConsoleOutputStream;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;



public class SeedShellConsole extends IOConsole implements Runnable
{
	private IOConsoleOutputStream outStream=null;
	int id;
	
	public SeedShellConsole(String name, ImageDescriptor imageDescriptor,int shellID)
	{
		super(name, imageDescriptor);
		outStream=newOutputStream();
		id=shellID;
		
		try
		{
			//SeedNotifier.instance.registerCallback("shell."+id,this,"print");
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
		new Thread(this).start();
	}

	public void print(Object output)
	{
		try
		{
			outStream.write(output.toString());
			outStream.flush();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public void run()
	{
		IOConsoleInputStream inStream=null;//getInputStream();
		inStream=this.getInputStream();
		
		byte[] buffer=new byte[20];
		int length;
		//SeedShellInterface shell=SeedConnector.instance.getShell(id);
		
		try
		{
			while(-1!=(length=inStream.read(buffer)))
			{
		//		shell.send(new String(buffer,0,length));
			}
		}
		catch(Exception e)
		{
			return;
		}
	}
}
